<template>
  <div class="hot-articles-item" @click="onDetail(data.resId)">
    <div class="index-box" :class="{rank1: index +1 === 1, rank2: index + 1 === 2, rank3: index + 1 === 3}">{{index+1}}</div>
    <div class="article-box">
      <div class="title">{{data.name}}</div>
      <div class="time">{{filterData(data.createDate)}}</div>
    </div>
  </div>
</template>

<script>
import moment from 'moment';
moment.locale('zh-cn');

export default {
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    },
    index: {
      type: Number,
      default() {
        return 1;
      }
    }
  },
  methods: {
    filterData(date) {
      let result
      const nowMM = new Date().getTime()
      if (nowMM - date < 604800000) {
        result = moment(date).startOf('hour').fromNow()
      } else {
        result = moment(date).format('ll')
      }
      return result    
    },
    onDetail(uuid) {
      let routerJump = this.$router.resolve({ name: 'InformationDetail', query: {uuid} });
      window.open(routerJump.href, '_blank');
    }
  }
}
</script>

<style lang="scss" scoped>
.hot-articles-item {
  overflow: hidden;
  border-bottom: 1px solid #F1F1F1;
  padding-top: 20px;
  background: #F9F9F9;
  cursor: pointer;
  .index-box {
    width: 20px;
    height: 20px;
    border-radius: 8px 0 8px 0;
    margin-right: 8px;
    float: left;
    background: #EFF2F6;
    font-size: 11px;
    font-family: Helvetica;
    color: #303741;
    line-height: 11px;
    line-height: 20px;
    text-indent: 8px;
    &.rank1 {
      background: linear-gradient(#FFE437, #FFC824);
    }
    &.rank2 {
      background: linear-gradient(#D0E0F6, #B0C3DF);
    }
    &.rank3 {
      background: linear-gradient(#FFE2AC, #F5CC9B);
    }
  }
  .article-box {
    width: calc(100% - 68px);
    float: left;
    .title {
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #272727;
      line-height: 20px;
      margin-bottom: 4px;
      word-break: break-all;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      word-break: break-all;
    }
    .time {
      font-size: 12px;
      
      font-weight: 400;
      color: #A8A8A8;
      line-height: 18px;
      margin-bottom: 12px;
    }
  }
}
</style>